<?php
defined('_JEXEC') or die('Restricted access'); 

jimport( 'joomla.html.html.tabs' );
JHtml::_('jquery.framework');
JHtml::_('behavior.keepalive');
JHTML::_('behavior.tooltip'); 
JHtml::_('behavior.framework');

?>
<script type="text/javascript">
	//<![CDATA[
	
	function check_outlet(){
		
		if(parseInt(jQuery('#o_code').val()) == -1 || isNaN(parseInt(jQuery('#o_code').val()))){
			jQuery("#o_code option").each(function() {
				if(parseInt(jQuery(this).val()) == -1)
					jQuery(this).removeAttr('selected');
				else	
		    		jQuery(this).attr('selected','selected');
			});
		}
	}
	
	Joomla.submitbutton = function(pressbutton){
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}
		if (pressbutton == 'save') {
			if (document.adminForm.title.value == "") {
				alert( 'Must have title !' );
				document.adminForm.title.focus();
				return false;
			}
			check_outlet();	
			submitform( pressbutton );
		}
	}

	jQuery(document).ready(function() {
		
		jQuery('#rule').change(function(){
			forLuckyNumber();
			forMultiples();
			forOrdinary();
		})
		
		function forLuckyNumber(){
			if(jQuery('#rule').val() != 5){
				jQuery('#lucky').val('').attr('readonly','readonly');
			}
			else{
				jQuery('#lucky').removeAttr('readonly');
			}
		}
		
		function forMultiples(){
			if(jQuery('#rule').val() != 4){
				jQuery('#multiples').val('').attr('readonly','readonly');
			}
			else{
				jQuery('#multiples').removeAttr('readonly');
			}
		}
		
		function forOrdinary(){
			if(jQuery('#rule').val() != 3){
				jQuery('#ordinary').val('').attr('readonly','readonly');
			}
			else{
				jQuery('#ordinary').removeAttr('readonly');
			}
		}
	});
</script>
<script type="text/javascript">
	
	var sectionprojects = new Array;
	var sectionclubs = new Array;
	<?php
		foreach ($this->lists['projectToClub'] as $k=>$item) {
			echo "sectionprojects[".$k."] = new Array( '$item->pid','".addslashes( $item->code )."','".addslashes( $item->name )."' );\n\t\t";
		}
	?>

	<?php 
		foreach ($this->lists['clubToOutlet'] as $k=>$item){
			echo "sectionclubs[".$k."] = new Array( '$item->cid','".addslashes( $item->code )."','".addslashes( $item->name )."' );\n\t\t";
	 	}
	 ?>
	function changeClubs( listname, source, key, orig_key, orig_val ) {
		var list = eval( 'document.adminForm.' + listname );
		// empty the list

		for (i in list.options.length) {
			list.options[i] = null;
		}

		var i = 0;
		var j = 0;
		for (x in source) {
			if (source[x][0] == key) {
				opt = new Option();
				opt.value = source[x][1];
				opt.text = source[x][2];

				if ((orig_key == key && orig_val == opt.value) || i == 0) {
					opt.selected = true;
					j = opt.value ;
				}
				list.options[i++] = opt;
			}
		}
		if(i == 0){
			opt = new Option();
			opt.value = '';
			opt.text = '- Select Clubs -';
			opt.selected = true;
			list.options[i++] = opt;
		}

		list.length = i;
		changeOutlets('o_code',sectionclubs,j,0,0);

	}
	
</script>
<form id="adminForm"  action="<?php echo JRoute::_("index.php?option=com_wrd&controller=discountoff")?>" method="post" name="adminForm">
	<div class="row-fluid">
	    <fieldset class="adminform">
	    	<legend><?php echo JText::_('Details')?></legend>
			<table class="table table-striped adminlist">
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Title')?>:</label>
					</td>
					<td colspan="2">
						<input type="text" title="type" maxlength="50" size="50" 
						value="<?php echo $this->data->title; ?>" id="title" name="title" class="title"/> *
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Projects')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['projects']; ?>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Clubs')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['clubs']; ?>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Outlets')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['outlets']; ?>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Publish up')?>:</label>
					</td>
					<td colspan="2">
						 <?php echo JHTML::_( 'calendar', ($this->data->published_up != '0000-00-00') ? $this->data->published_up : '' , 'published_up', 'published_up','%Y-%m-%d', 'size="15"'); ?>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Publish down')?>:</label>
					</td>
					<td colspan="2">
						 <?php echo JHTML::_( 'calendar', ($this->data->published_down != '0000-00-00') ? $this->data->published_down : '' , 'published_down', 'published_down','%Y-%m-%d', 'size="15"'); ?>
					</td>
				</tr>
				
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Percent')?>:</label>
					</td>
					<td colspan="2">
						<input type="text" title="type" maxlength="50" size="50" 
						value="<?php echo $this->data->percent != 0 ? $this->data->percent : 0; ?>" 
						id="point" name="percent" class="percent"/>(%) *
						(Ex: 15)
					</td>
				</tr>
				
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Cash')?>:</label>
					</td>
					<td colspan="2">
						<input type="text" title="type" maxlength="50" size="50" 
						value="<?php echo $this->data->cash != 0 ? $this->data->cash : 0; ?>" 
						id="cash" name="cash" class="cash"/> *
						(Ex: 200000)
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Rule')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['rule']; ?>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Lucky Nymber')?>:</label>
					</td>
					<td colspan="2">
						<input type="text" title="type" maxlength="50" size="50" 
						value="<?php echo $this->data->lucky  ?>" id="lucky" name="lucky" class="lucky"/> *
						(Ex: 15,25,35,45,55)
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Priority')?>:</label>
					</td>
					<td colspan="2">
						<input type="text" title="type" maxlength="50" size="50" 
						value="<?php echo $this->data->priority  ?>" id="priority" name="priority" class="priority"/> * (Ex: 1 or 5 or 9)
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Message')?>:</label>
					</td>
					<td colspan="2">
						
						<textarea name="message" cols="10" rows="5"><?php echo $this->data->message; ?></textarea>
					</td>
				</tr>
				<tr style="display:none">
					<td class="key">
						<label for="title"><?php echo JText::_('Publish')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['published']; ?>
					</td>
				</tr>
            </table>
		</fieldset>
	</div>
	
	<input type="hidden" name="created_id" value="<?php echo $this->user->id;?>" />
	<input type="hidden" name="controller" value="discountoff" />
	<input type="hidden" name="option" value="com_wrd" />
	<input type="hidden" name="id" value="<?php echo (int)$this->data->id; ?>" />
	<input type="hidden" name="task" value="" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>
